<%@ page language="java" import="com.util.StringFinal" contentType="text/html; charset=utf-8" pageEncoding="utf-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions"%>
<%
	String userid = request.getSession().getAttribute("user_id") == null
			? ""
			: request.getSession().getAttribute("user_id").toString();
	String rolename = request.getSession().getAttribute("role_name") == null
	? ""
	: request.getSession().getAttribute("role_name").toString();
%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<link rel="stylesheet" type="text/css" href="../../bootstrap-3.3.7/dist/css/bootstrap.min.css" />
<link rel="stylesheet" type="text/css" href="../../bootstrap-3.3.7/dist/css/bootstrap-theme.min.css" />
<link rel="stylesheet" type="text/css" href="../../css/index.css" />
<link rel="stylesheet" type="text/css" href="../../css/infosearch.css" />
<link href="../../css/comment/main.css" rel="stylesheet" type="text/css">

<script type="text/javascript" src="../../bootstrap-3.3.7/dist/js/jquery.min.js"></script>
<script type="text/javascript" src="../../bootstrap-3.3.7/dist/js/bootstrap.js"></script>

<!-- bootstrap表格插件 -->
<script src="../../bootstrap-3.3.7/dist/js/bootstrap-table.js"></script>
<link href="../../bootstrap-3.3.7/dist/css/bootstrap-table.css" rel="stylesheet" />
<script src="../../bootstrap-3.3.7/dist/js/bootstrap-table-zh-CN.js"></script>
<!-- IE10 viewport hack for Surface/desktop Windows 8 bug -->
<link href="../../bootstrap-3.3.7/docs/assets/css/ie10-viewport-bug-workaround.css" rel="stylesheet">
<!-- HTML5 shim and Respond.js for IE8 support of HTML5 elements and media queries -->
<script src="https://oss.maxcdn.com/html5shiv/3.7.3/html5shiv.min.js"></script>
<script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
<script type="text/javascript" src="../../js/bootstrap-paginator.js"></script>
<script type="text/javascript" src="../../js/wordcontrol.js"></script>
</head>
<body>
	<div class="container">
		<div class="row clearfix">
			<div class="col-md-12 column">
				<%@include file="../common/header.jsp"%>
			</div>
			<div class="col-md-12 column" style="padding-top: 20px">
				<div class="col-md-6">
					<div class="input-group">
						<input type="text" id="search_content" class="form-control" placeholder="请输入要搜索的内容"> <span class="input-group-btn">
							<button class=" btn btn-warning" type="button" onclick="seacrh('')">
								<span class="myfont">检索</span>
							</button>
						</span>
					</div>
				</div>
				<div class="col-md-3">
					<div class="input-group" style="margin-top: 15px">
						<a href="../information/infoadsearch.jsp"><span style="font-size: 28;" class="text-primary">高级检索</span></a>
					</div>
				</div>
				<div class="col-md-3"></div>
			</div>
		</div>
		<div class="row clearfix">
			<div class="col-md-9 column">
				<h4 class="heading">知识详情</h4>
				<div class="myline"></div>
				<div class="panel panel-default">
					<div class="row">
						<div class="col-md-8" style="margin-left: 40px">
							<h4 class="myfont">
								<span style="font-family:宋体" class="text-primary">${info.info_name}</span>
							</h4>
						</div>
						
						<div class="col-md-3" style="margin-top: 15px;" >
							<span style="color: black; float: right; margin-right: 10px; margin-top: 2px">${info.info_browser}</span> <img class="img-thumbnail" data-toggle="popover"
								data-trigger="hover" title="浏览量" style="height: 25px; width: 25px; border: none; float: right" src="../../image/icon/eye.png">

							<div hidden="true" id="mycollectimage">
								<span id="collectCount" style="color: black; float: right; margin-right: 10px; margin-top: 2px">${goodcount}</span> <img id="collectimage" class="img-thumbnail"
									data-toggle="popover" data-trigger="hover" title="收藏" style="height: 25px; width: 25px; border: none; float: right" src="${collectimage}"> 
								<span id="thumbsupCount" style="color: black; float: right; margin-right: 10px; margin-top: 2px">${thumbsupcount}</span> <img id="thumbsupimage" class="img-thumbnail" 
								    data-toggle="popover" data-trigger="hover" title="点赞" style="height: 25px; width: 25px; border: none; float: right" src="${thumbsupimage}">
							</div>					
						</div>
					</div>

					<ul style="margin-left: 40px">
						<li class="myfont">摘要：<span style="color: #707070;font-family:宋体">${info.info_abstract}</span></li>
						<li class="myfont">关键词：<span style="color: #707070;font-family:宋体">${info.info_keyword}</span></li>
						<c:if test="${not empty info.info_author}">
							<li class="myfont">作者：<span style="color: #707070;font-family:宋体">${info.info_author}</span></li>
						</c:if>
						<c:if test="${not empty info.info_company}">
							<li class="myfont">作者单位：<span style="color: #707070;font-family:宋体">${info.info_company} </span></li>
						</c:if>
						<c:if test="${not empty info.info_source}">
							<li class="myfont">文献来源：<span style="color: #707070;font-family:宋体">${info.info_source} </span></li>
						</c:if>
						<c:if test="${not empty info.info_bm}">
							<li class="myfont">发布部门：<span style="color: #707070;font-family:宋体">${info.info_bm}</span></li>
						</c:if>
						<c:if test="${not empty info.info_time}">
							<li class="myfont">发表日期：<span style="color: #707070;font-family:宋体">${info.info_time}</span></li>
						</c:if>
						<c:if test="${not empty info.user_name}">
							<li class="myfont">上传者：<span style="color: #707070;font-family:宋体">${info.user_name}</span></li>
						</c:if>
						<c:if test="${not empty info.info_wh}">
							<li class="myfont">文号：<span style="color: #707070;font-family:宋体">${info.info_wh}</span></li>
						</c:if>
						<li class="myfont">下载：<a href='#' data-id="${info.info_id}" onclick="down('${info.info_url}','${info.info_id}','${info.info_status}','${info.info_level}')"><span style="font-family:宋体" class="text-primary">${download_name}</span></a><a class="text-primary" onclick='viewinfo("${info.info_url }")' <%-- href='../infocenter/preview?infourl=${info.info_url }' target="_blank"--%> >&nbsp;&nbsp;&nbsp;&nbsp;预览</a></li>
						<li >（提示：初次下载知识需要扣除${downpoint}积分，重复下载不扣除积分，每评论一条知识可获取${uppoint}积分）</li>
					</ul>
					<input type="text" id="info_id" value="${info.info_id}" hidden="true">
					<input type="text" id="info_keyword" value="${info.info_keyword}" hidden="true">
					<input type="text" id="info_level" value="${info.info_level}"  hidden="true">
				</div>		
			</div>
			<div class="col-md-3 column">
				<h4 class="heading">推荐列表</h4>
				<div class="myline"></div>
				<ul id="recommendlist">

				</ul>
			</div>
			<div class="col-md-12">
				<!-- 普通用户评论框 -->
				<div class="col-md-9" >
					<div class="row" id="comment">
						<textarea id="reply_content" onKeyUp="ControlWordCount(&quot;reply_content&quot;,&quot;reply_count&quot;,<%=StringFinal.comment_length%>)" rows="6" style="width:100%" placeholder="请对知识发表您的评论"></textarea>
						<button type="button" class="btn btn-default" onclick="addContent()" style="float: right; margin-left: 5px">发表评论</button>
						<p style="float: right; margin-top: 5px">
							你还可以输入<span id="reply_count"><%=StringFinal.comment_length%></span>个字
						</p>
					</div>
					<!-- 专家用户评论框 -->
					<div class="row" id="specialist_comment">
							<textarea id="specialist_reply_content" onKeyUp="ControlWordCount(&quot;specialist_reply_content&quot;,&quot;specialist_reply_count&quot;,<%=StringFinal.comment_length%>)" rows="6" style="width:100%"  placeholder="请专家对知识发表您的评论"></textarea>
							<button type="button" class="btn btn-default" onclick="addCommentSpecialist()" style="float: right; margin-left: 5px">发表评论</button>
							<p style="float: right; margin-top: 5px">
								你还可以输入<span id="specialist_reply_count"><%=StringFinal.comment_length%></span>个字
							</p>
					</div>
					<div class="row">
							<h4 class="myfont">专家点评</h4>
							<p id="specialist_tip" align="center"></p>
							<ul class="media-list" id="second_comment">
							</ul>
							<div class="row">
								<div class="col-md-3"></div>
								<ul id="paginator_specialist" style="padding-left: 40px;"></ul>
							</div>
					</div>
					<div class="row" style="margin-top: 20px;">
							<h4 class="myfont">用户评论</h4>
							<p id="tip" align="center"></p>
							<ul class="media-list" id="first_comment">
		
							</ul>
							<div class="row">
								<div class="col-md-3"></div>
								<ul id="paginator" style="padding-left: 40px"></ul>
							</div>
					</div>
				</div>
				<div class="col-md-3" id="user">
				<h4 class="heading">领域专家</h4>
				<div class="myline"></div>
				<ul class="myul">
					<c:forEach items="${listzj}" var="zj">
						<c:choose>
							<c:when test="${empty zj.userzj_picture}">
								<li><img class="img-thumbnail" src="../../image/user/default.jpg" style="width:90px;height:120px"> <a href="../specialist/getZJDetail?zjid=${zj.userzj_id}"><span
										class="text-primary" style="padding-left: 30px">${zj.userzj_name}</span></a></li>
							</c:when>
							<c:otherwise>
								<li><img class="img-thumbnail" src="../../image/user/${zj.userzj_picture}" style="width:90px;height:120px"> <a href="../specialist/getZJDetail?zjid=${zj.userzj_id}"><span
										class="text-primary" style="padding-left: 30px">${zj.userzj_name}</span></a></li>
							</c:otherwise>
						</c:choose>
					</c:forEach>
				</ul>
				<a href="../specialist/getSpecialistview" style="float: right"><span class="text-primary">更多</span></a>
				</div>
			</div>
		</div>
		<div class="myline" style="margin-top: 20px"></div>

		<div class="row clearfix">
			<div class="col-md-12 column">
				<%@include file="../common/bottom.jsp"%>
			</div>
		</div>
	</div>
</body>
<script type="text/javascript">
var role='<%=rolename%>';
//标记是给知识回复还是给人回复,初始为0表示给知识回复，1表示给人回复
var replyother=0;
var replyuserid;
var replyusername;
var replypid;
//当前登录用户id
var userid = '<%=userid%>';
//每一页显示几条评论 
var rows=2;
//当前页中评论的总条数
//当前页面评论区浏览到第几页
var currentpage;
var totalpage;
/**************************************************************/
var sp_currentpage;
var sp_totalpage;

$(document)
.ready(
		function() {
			var userid = '<%=userid%>';
			var status = '${info.info_status}';
						if (userid != "" && status == '通过') {
							$("#mycollectimage").show();
						}

						// 点赞
						$('#thumbsupimage')
								.click(
										function() {
											//已经点赞了该知识，点击取消点赞
											if ($(this).attr('src') == '../../image/icon/like-red.png') {
												$
														.ajax({
															async : false,
															cache : false,
															type : 'POST',
															dataType : "json",
															data : {
																"user_id" : "",
																"info_id" : $(
																		'#info_id')
																		.val(),
																"time" : ""
															},
															url : "../information/deleteThumbsUp",
															error : function() {
																alert('请求失败');
															},
															success : function(
																	data) {
																if (data == 1) {
																	$(
																			'#thumbsupimage')
																			.attr(
																					'src',
																					'../../image/icon/like-black.png');
																	var count = parseInt($(
																			'#thumbsupCount')
																			.html()) - 1;
																	$(
																			'#thumbsupCount')
																			.html(
																					count);
																}
															}
														});//AJAX结束      		
											}
											//还没有点赞该知识，点击收藏点赞
											else {
												$
														.ajax({
															async : false,
															cache : false,
															type : 'POST',
															dataType : "json",
															data : {
																"user_id" : "",
																"info_id" : $(
																		'#info_id')
																		.val(),
																"time" : ""
															},
															url : "../information/addThumbsUp",
															error : function() {
																alert('请求失败');
															},
															success : function(
																	data) {
																if (data == 1) {
																	$(
																			'#thumbsupimage')
																			.attr(
																					'src',
																					'../../image/icon/like-red.png');
																	var count = parseInt($(
																			'#thumbsupCount')
																			.html()) + 1;
																	$(
																			'#thumbsupCount')
																			.html(
																					count);
																}
															}
														});//AJAX结束              	
											}
										});

						$('#collectimage')
								.click(
										function() {
											//已经收藏了该知识，点击取消收藏
											if ($(this).attr('src') == '../../image/icon/star-full.png') {
												$
														.ajax({
															async : false,
															cache : false,
															type : 'POST',
															dataType : "json",
															data : {
																"user_id" : "",
																"id" : $(
																		'#info_id')
																		.val(),
																"time" : ""
															},
															url : "../infocenter/deleteCollection",
															error : function() {
																alert('请求失败');
															},
															success : function(
																	data) {
																if (data == 1) {
																	$(
																			'#collectimage')
																			.attr(
																					'src',
																					'../../image/icon/star-empty.png');
																	var count = parseInt($(
																			'#collectCount')
																			.html()) - 1;
																	$(
																			'#collectCount')
																			.html(
																					count);
																}
															}
														});//AJAX结束      		
											}
											//还没有收藏该知识，点击收藏知识
											else {
												$
														.ajax({
															async : false,
															cache : false,
															type : 'POST',
															dataType : "json",
															data : {
																"user_id" : "",
																"id" : $(
																		'#info_id')
																		.val(),
																"time" : ""
															},
															url : "../infocenter/addCollection",
															error : function() {
																alert('请求失败');
															},
															success : function(
																	data) {
																if (data == 1) {
																	$(
																			'#collectimage')
																			.attr(
																					'src',
																					'../../image/icon/star-full.png');
																	var count = parseInt($(
																			'#collectCount')
																			.html()) + 1;
																	$(
																			'#collectCount')
																			.html(
																					count);
																}
															}
														});//AJAX结束              	
											}				
										});
					})

	$(function() {
		getRecommendlist();
		//初始化普通用户评论
		calculatetotalpage();
		currentpage = 1;
		initComment(1);
		
		//初始化专家评论
		SP_calculatetotalpage();
		sp_currentpage = 1;
		initCommentSpecialist(1);

		if (role != "专家") {
			//隐藏专家评论框
			$('#specialist_comment').hide();
			ControlWordCount("comment");
		} else {
			//隐藏普通用户评论框
			$('#comment').hide();
			ControlWordCount("specialist_comment")
		}
		 var counter = 0;
         if (window.history && window.history.pushState) {
                          $(window).on('popstate', function () {
                                     
                      		   window.history.back(-1);	
                             });
           }
	});

	//分页——计算出totalpage(专家)
	function SP_calculatetotalpage() {
		$.ajax({
			url : '../information/getCommentSpecialistCount',
			type : 'get',
			async : false,
			data : {
				"comment_specialist_infoid" : $('#info_id').val()
			},
			success : function(result) {
				if (result != 0) {
					if (result % rows == 0) {
						sp_totalpage = parseInt(result / rows);
					}
					if (result % rows != 0) {
						sp_totalpage = parseInt(result / rows) + 1;
					}
					$("#specialist_tip").html("");
					sp_paginator(sp_totalpage);
				} else {
					$("#specialist_tip").html("还没有专家进行点评");
					$("#paginator_specialist").html("");
				}
			}
		});
	}
	function sp_paginator(value) {
		var element = $('#paginator_specialist');
		var options = {
			bootstrapMajorVersion : 3, //对应的bootstrap版本
			currentPage : 1, //当前页数，这里是用的EL表达式，获取从后台传过来的值
			numberOfPages : rows, //每页页数
			totalPages : value, //总页数，这里是用的EL表达式，获取从后台传过来的值
			shouldShowPage : true,//是否显示该按钮
			listContainerClass:"pagefenye",
			itemContainerClass: function (type, page, current) {
	            return (page === current) ? "active" : "";
	        },
	        itemContentClass: function (type, page, current) {
	            return "";
	        },
			 itemTexts : function(type, page, current) {//设置显示的样式，默认是箭头
				switch (type) {
					case "first" :
						return "首页"; 
					case "prev" :
						return "上一页";
					case "next" :
						return "下一页";
					 case "last" :
						return "末页"; 
					case "page" :
						return page;
				} 
			},
			onPageClicked : function(event, originalEvent, type, page) {
				sp_currentpage = page;
				initCommentSpecialist(page);
			}
		};
		element.bootstrapPaginator(options);
	}

	//初始化用户评论(专家)
	function initCommentSpecialist(page) {
		$
				.ajax({
					async : false,
					cache : false,
					type : 'POST',
					dataType : "json",
					data : {
						"page" : (page - 1) * rows,
						"rows" : rows,
						"comment_specialist_infoid" : $('#info_id').val()
					},
					url : "../information/getCommentSpecialistList",
					error : function() {
						alert('请求失败');
					},
					success : function(data) {
						$("#second_comment").html("");
						if (data.length > 0) {

							var str = "";
							for (var i = 0; i < data.length; i++) {
								str += '<li class="media" id="specialist_li_'+data[i].comment_specialist_id+'">';
								str += '<div class="media-left">';
								str += '<a href="#"> <img class="media-object img-circle" src="../../image/user/'+data[i].picture_specialist_url+'" style="width: 66px; height: 66px;"  alt="专家"></a>';
								str += '</div>'; 
								str += '<div class="media-body">';
								str += '<h5 class="myfont">'
										+ data[i].comment_specialist_username
										+ '</h5>';
								str += '<p>'
										+ data[i].comment_specialist_content
										+ '</p>';
								str += '<div class="ds-comment-footer">';
								str += '<span class="ds-time" datetime="2016-01-28T20:13:29+08:00" title="2016年1月28日 下午8:13:29">'
										+ data[i].comment_specialist_time
										+ '</span>&nbsp;';
								if (data[i].comment_specialist_userid == userid || role=='知识管理员') {
									str += '<div style="float: right;"><a onclick="deleteCommentSpecialist(&quot;'
											+ data[i].comment_specialist_id
											+ '&quot;)"><span>删除</span></a></div>';
								}
								str += '</div><hr />';
								str += '</div>';
								str += '</li>';
							}
							$("#second_comment").append(str);
						}
					}
				});//AJAX结束   
	}
	//对知识的评论(普通用户)
	function addCommentSpecialist() {
		if ($('#specialist_reply_content').val() == "") {
			alert("请输入评论内容");
			return;
		}
		var id = "";
		$.ajax({
			async : false,
			cache : false,
			type : 'POST',
			dataType : "json",
			data : {
				"comment_specialist_content" : $('#specialist_reply_content')
						.val().replace(/ /g,"&nbsp").replace(/[\n\r]/g, "<br>"),
				"comment_specialist_infoid" : $('#info_id').val()
			},
			url : "../information/addCommentSpecialist",
			error : function() {
				alert('请求失败');
			},
			success : function(data) {
				if (data == 1) {
					$('#specialist_reply_content').val("");
					sp_currentpage = 1;
					SP_calculatetotalpage();
					initCommentSpecialist(sp_currentpage);
				}
			}
		});//AJAX结束   
	}
	//删除评论(普通用户)
	function deleteCommentSpecialist(id) {
		$.ajax({
			async : false,
			cache : false,
			type : 'POST',
			dataType : "json",
			data : {
				"id" : id
			},
			url : "../information/deleteCommentSpecialist",
			error : function() {
				alert('请求失败');
			},
			success : function(data) {
				if (data != 0) {
					SP_calculatetotalpage();
					initCommentSpecialist(sp_currentpage);
				}
			}
		});//AJAX结束 

	}
	/********************************************************************************************************************************************/
	//分页——计算出totalpage(普通用户)
	function calculatetotalpage() {
		$.ajax({
			url : '../information/getCommentCount',
			type : 'get',
			async : false,
			data : {
				"comment_infoid" : $('#info_id').val()
			},
			success : function(result) {
				if (result != 0) {
					if (result % rows == 0) {
						totalpage = parseInt(result / rows);
					}
					if (result % rows != 0) {
						totalpage = parseInt(result / rows) + 1;
					}
					$("#tip").html("");
					paginator(totalpage);

				} else {
					$("#tip").html("还没有评论");
					$("#paginator").html("");
				}
			}
		});
	}
	function paginator(value) {
		var element = $('#paginator');
		var options = {
			bootstrapMajorVersion : 3, //对应的bootstrap版本
			currentPage : 1, //当前页数，这里是用的EL表达式，获取从后台传过来的值
			numberOfPages : rows, //每页页数
			totalPages : value, //总页数，这里是用的EL表达式，获取从后台传过来的值
			shouldShowPage : true,//是否显示该按钮
			 itemTexts : function(type, page, current) {//设置显示的样式，默认是箭头
				switch (type) {
					case "first" :
						return "首页";
					case "prev" :
						return "上一页";
					case "next" :
						return "下一页";
					case "last" :
						return "末页";
					case "page" :
						return page;
				}
			}, 
			onPageClicked : function(event, originalEvent, type, page) {
				currentpage = page;
				initComment(page);
			}
		};
		element.bootstrapPaginator(options);
	}

	//发表评论(普通用户)
	function addContent() {
		 if (userid != '') {
			if (replyother == 0) {
				addComment();
			}
			if (replyother == 1) {
				addReply();
				replyother = 0;
			}
		} else {
			alert("请您先登录");
		} 
		
	}
	//对评论的回复(普通用户)
	function addReply() {
		if ($('#comment textarea').val() == "") {
			alert("请输入评论内容");
			return;
		}
		$.ajax({
			async : false,
			cache : false,
			type : 'POST',
			dataType : "json",
			data : {
				"comment_parentid" : replypid,
				"comment_touserid" : replyuserid,
				"comment_content" : $('#comment textarea').val().replace(/ /g,"&nbsp").replace(/[\n\r]/g, "<br>")
			},
			url : "../information/addComment",
			error : function() {
				alert('请求失败');
			},
			success : function(data) {
				if (data == 1) {
					//针对某条评论回复之后在评论下方显示
					$('#replydiv_' + replypid + ' span').html(
							parseInt($('#replydiv_' + replypid + ' span')
									.html()) + 1);
					$('#replydiv_' + replypid).show();
					$('#image_' + replypid).attr('src',
							'../../image/icon/down.png');
					downreply(replypid);
				}
			}
		});//AJAX结束
		$('#reply_content').val("");
		$("#reply_content").attr('placeholder', "请对知识发表您的评论");
	}
	//对知识的评论(普通用户)
	function addComment() {
		if ($('#reply_content').val() == "") {
			alert("请输入评论内容");
			return;
		}
		var id = "";
		$.ajax({
			async : false,
			cache : false,
			type : 'POST',
			dataType : "json",
			data : {
				"comment_content" : $('#reply_content').val().replace(/ /g,"&nbsp").replace(/[\n\r]/g, "<br>"),
				"comment_infoid" : $('#info_id').val()
			},
			url : "../information/addComment",
			error : function() {
				alert('请求失败');
			},
			success : function(data) {
				if (data == 1) {
					$('#reply_content').val("");
					calculatetotalpage();
					initComment(1);
				}
			}
		});//AJAX结束   
	}

	//点击向下图标获取某条评论的回复(普通用户)
	function downreply(id) {
		if ($('#image_' + id).attr('src') == '../../image/icon/down.png') {
			$('#image_' + id).attr('src', '../../image/icon/up.png');
			$
					.ajax({
						async : false,
						cache : false,
						type : 'POST',
						dataType : "json",
						data : {
							"type" : "asc",
							"comment_parentid" : id
						},
						url : "../information/getCommentList",
						error : function() {
							alert('请求失败');
						},
						success : function(data) {
							if (data.length > 0) {
								$("#reply_" + id).html("");
								var str = "";
								for (var i = 0; i < data.length; i++) {
									str += '<li class="media" id="li_'+data[i].comment_id+'">';
									str += '<div class="media-left"><a href="#"> <img class="media-object img-circle" src="../../image/user/'+data[i].picture_url+'" style="width: 66px; height: 66px;" alt="用户"></a></div>';
									str += '<div class="media-body">';
									str += '<h5 class="myfont">'
											+ data[i].comment_username + ':';
									if (data[i].comment_tousername != "") {
										str += '&nbsp;&nbsp;回复&nbsp;&nbsp;'
												+ data[i].comment_tousername
												+ ':</h5>';
									} else {
										str += '</h5>';
									}
									str += '<p>' + data[i].comment_content
											+ '</p>';
									str += '<div class="ds-comment-footer">';
									str += '<span class="ds-time" datetime="2016-01-28T20:13:29+08:00" title="2016年1月28日 下午8:13:29">'
											+ data[i].comment_time
											+ '</span>&nbsp;';
									if (role != "专家") {
										str += '<a onclick="reply(&quot;'
												+ data[i].comment_userid
												+ '&quot;,&quot;'
												+ data[i].comment_username
												+ '&quot;,&quot;'
												+ id
												+ '&quot;)"> <span class="glyphicon glyphicon-comment" aria-hidden="true"></span> 回复 </a>';

									}
									str += '</div>';
									if (data[i].comment_userid == userid || role=='知识管理员') {
										str += '<div style="float: right;"><a onclick="deleteComment(&quot;'
												+ data[i].comment_id
												+ '&quot;,&quot;'
												+ id
												+ '&quot;)"><span>删除</span></a></div>';
									}
									str += '</div>';
									str += '</li>';
								}
								$("#reply_" + id).append(str);
							}
						}
					});//AJAX结束	
			return;
		}
		if ($('#image_' + id).attr('src') == '../../image/icon/up.png') {
			$('#image_' + id).attr('src', '../../image/icon/down.png');
			$("#reply_" + id).html("");
			return;
		}
	}
	//设置回复框内位置，设置光标位置(普通用户)
	function reply(userid, username, pid) {
		$("#reply_content").attr('placeholder', "回复 " + username + ":");
		setCaretPosition(document.getElementById("reply_content"), 0);
		replyuserid = userid;
		replyusername = username;
		replypid = pid;
		replyother = 1;
	}
	//删除评论(普通用户)
	function deleteComment(id, pid) {
		$.ajax({
			async : false,
			cache : false,
			type : 'POST',
			dataType : "json",
			data : {
				"id" : id
			},
			url : "../information/deleteComment",
			error : function() {
				alert('请求失败');
			},
			success : function(data) {
				if (data != 0) {
					calculatetotalpage();
					initComment(currentpage);
					if (pid != "") {
						downreply(pid);
					}
				}
			}
		});//AJAX结束 

	}
	//初始化普通用户评论(普通用户)
	function initComment(page) {
		$
				.ajax({
					async : false,
					cache : false,
					type : 'POST',
					dataType : "json",
					data : {
						"type" : "desc",
						"page" : (page - 1) * rows,
						"rows" : rows,
						"comment_infoid" : $('#info_id').val()
					},
					url : "../information/getCommentList",
					error : function() {
						alert('请求失败');
					},
					success : function(data) {
						$("#first_comment").html("");
						if (data.length > 0) {

							var str = "";
							for (var i = 0; i < data.length; i++) {
								str += '<li class="media" id="li_'+data[i].comment_id+'">';
								str += '<div class="media-left">';
								str += '<a href="#"> <img class="media-object img-circle" src="../../image/user/'+data[i].picture_url+'" style="width: 66px; height: 66px;" alt="用户"></a>';
								str += '</div>';
								str += '<div class="media-body">';
								str += '<h5 class="myfont">'
										+ data[i].comment_username + '</h5>';
								str += '<p>' + data[i].comment_content + '</p>';
								str += '<div class="ds-comment-footer">';
								str += '<div style="float: left;">';
								str += '<span class="ds-time" datetime="2016-01-28T20:13:29+08:00" title="2016年1月28日 下午8:13:29">'
										+ data[i].comment_time
										+ '</span>&nbsp;';
								if (role != "专家") {
									str += '<a onclick="reply(&quot;'
											+ data[i].comment_userid
											+ '&quot;,&quot;'
											+ data[i].comment_username
											+ '&quot;,&quot;'
											+ data[i].comment_id
											+ '&quot;)"><span class="glyphicon glyphicon-comment" aria-hidden="true"></span>回复</a>';
								}
								str += '</div>&nbsp;';
								if (data[i].reply_count == 0) {
									str += '<div id="replydiv_'+data[i].comment_id+'" hidden="true" style="float: left;">&nbsp;&nbsp;';
									str += '<img id="image_'
											+ data[i].comment_id
											+ '" onclick="downreply(&quot;'
											+ data[i].comment_id
											+ '&quot;)" style="height:15px;width:15px;" src="../../image/icon/down.png">';
									str += '<span>' + data[i].reply_count
											+ '</span>条回复</div>';
								} else {
									str += '<div id="replydiv_'+data[i].comment_id+'" style="float: left;">&nbsp;&nbsp;';
									str += '<img id="image_'
											+ data[i].comment_id
											+ '" onclick="downreply(&quot;'
											+ data[i].comment_id
											+ '&quot;)" style="height:15px;width:15px;" src="../../image/icon/down.png">';
									str += '<span>' + data[i].reply_count
											+ '</span>条回复</div>';
								}
								if (data[i].comment_userid == userid || role =='知识管理员') {
									str += '<div style="float: right;"><a onclick="deleteComment(&quot;'
											+ data[i].comment_id
											+ '&quot;,&quot;&quot;)"><span>删除</span></a></div>';
								}
								str += '</div><hr />';
								str += '<ul class="media-list" id="reply_'+data[i].comment_id+'"></ul>';
								str += '</div>';
								str += '</li>';
							}
							$("#first_comment").append(str);
						}
					}
				});//AJAX结束   
	}

	//获取光标
	function getCursortPosition(ctrl) {//获取光标位置函数  
		var CaretPos = 0; // IE Support  
		if (document.selection) {
			ctrl.focus();
			var Sel = document.selection.createRange();
			Sel.moveStart('character', -ctrl.value.length);
			CaretPos = Sel.text.length;
		}
		// Firefox support  
		else if (ctrl.selectionStart || ctrl.selectionStart == '0')
			CaretPos = ctrl.selectionStart;
		return (CaretPos);
	}
	//设置光标位置 
	function setCaretPosition(ctrl, pos) {//设置光标位置函数  
		if (ctrl.setSelectionRange) {
			ctrl.focus();
			ctrl.setSelectionRange(pos, pos);
		} else if (ctrl.createTextRange) {
			var range = ctrl.createTextRange();
			range.collapse(true);
			range.moveEnd('character', pos);
			range.moveStart('character', pos);
			range.select();
		}
	}

	function down(url,infoid,status,level){
		
		if (userid != '') {
			//level为2表示是vip
			if(role=="vip用户"||role=="知识管理员"||role=="超级知识管理员")
			{
				var url = encodeURI("../information/p_downloadn?filename=" + url+"&infoid="+infoid+"&status="+status);
				window.location.href =url;
			}
			else
			{
				if(level==2) {
					alert("该条知识是vip知识,您不具有下载权限");
					return;
				}
				else
				{
					var result = getJg();
					if(result==0){
						alert("您的积分不足，不能进行下载");
						return;
					}
					else
					{
					var url = encodeURI("../information/p_downloadn?filename=" + url+"&infoid="+infoid+"&status="+status);
					window.location.href =url;
					}
				}
			}
		} else {
			alert("请您先登录");
		} 
	}
	//查看知识详情
	function check(id,keyword) {
		var url = encodeURI("../information/getInfoDetial?info_id="+id+"&keyword="+keyword);
		//window.location.href =url;
		window.open(url);
	}
	function seacrh(rezsk_id) {
		var content = $("#search_content").val();
		if (content == "") {
			alert("请输入检索内容");
			return;
		}
		window.location.href = "getSearchInfo?category=name&content=" + content
				+ "&reczsk_id=" + rezsk_id;
	}
	//查找积分是否允许下载
	 function getJg(){
		   var jg = 0;
			$.ajax({
				url:"../information/getPermitload",
				async:false,
				data:"userid="+userid,
				success:function(result){
					jg= result;
				}
			});
			return jg;
	 }
	function getRecommendlist(){
		$.ajax({
			url:"../information/getRecommendlist",
			async:true,
			dataType:"json",
			data:{
				"info_id":$("#info_id").val(),
				"keyword":$("#info_keyword").val()
			},
			success:function(data){
				 if(data.length>0){
					var str="";
					for(var i =0;i<data.length;i++){
						var infoname = data[i].info_name
						if(infoname.length>18)
						{
							str +='<li style="padding-top: 10px"><span class="text-primary"><a href="javascript:void(0)" data-toggle="popover" data-trigger="hover" title="'+infoname+'"onclick="check(&quot;'+data[i].info_id+'&quot;,&quot;'+data[i].info_keyword+'&quot;)">'+infoname.substring(0,16)+'.....</a></span></li>';
						}
						else{
							str +='<li style="padding-top: 10px"><span class="text-primary"><a href="javascript:void(0)" data-toggle="popover" data-trigger="hover" title="'+infoname+'"onclick="check(&quot;'+data[i].info_id+'&quot;,&quot;'+data[i].info_keyword+'&quot;)">'+infoname+'</a></span></li>';
						}
					}
					$("#recommendlist").append(str);
				} 
				
			}
		});
		
	}
	function viewinfo(infourl){
		if(role=="普通用户")
		{
			var point = getPerpoint();
			alert(point);
			if(point <=0){
				alert("您的积分不足，不能浏览文件");
				return;
			}
		}
		var arr = infourl.split(".");
		var src;
		if(arr[1].indexOf("pdf")!=-1||arr[1].indexOf("doc")!=-1||arr[1].indexOf("ppt")!=-1||arr[1].indexOf("xls")!=-1){
			
			if(arr[1].indexOf("pdf")==-1)
				 src = encodeURI("view/"+infourl.split("/")[1].split(".")[0]+".pdf");
			else
				 src =  encodeURI(infourl);
			  	window.open('../../pdfjs/web/viewer.html?file=../../'+src,'_blank','width:50%;height:50%;top:100;left:100;');
		}
		else
			alert("不支持该格式的文件预览,office,pdf格式的预览");
	}
	//查找个人积分
	 function getPerpoint(){
		   var jg;
			$.ajax({
				url:"../information/getPersonpoint",
				async:false,
				data:"userid="+userid,
				success:function(result){
					jg= result;
				}
			});
			return jg;
	 }
</script>
</html>